package p2pcdnsim.network;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;


public class RouterNode implements Node {
	
	private int id;
	private NetworkLayer net;
	private HashMap<String,Link> links;
	
	//The bus supposed to attach local machines, for instance, clients in a CDN
	private LANBus bus;


	public RouterNode(int nodeID) {
		this.id = nodeID;
		links = new HashMap<String,Link>();
	}

	public long getNodeId() {
		return id;
	}
	
	public void addLink(Link link)  {
		this.links.put(link.getLinkId() , link);
	}
	
	public List<Link> getLinks() {
		return new ArrayList<Link>(links.values());
	}


	public void setNetworkLayer(NetworkLayer net) {
		this.net = net;
		net.setNode(this);
	}

	public void receivePacket(Packet p) {
		if(net!=null)
			net.addPacket(p);
	}

	public NetworkLayer getNetworkLayer() {
		return net;
	}

	public Link getDefaultLink() {
		return links.values().iterator().next();
	}

	public void setLinkBus(LANBus bus) {
		this.bus = bus;
	}
	
	public LANBus getLinkBus() {
		return bus;
	}

	@Override
	public String getName() {
		return "RouterNode"+id;
	}

}
